package cn.shujuhai.workflow.controller.form;


import cn.shujuhai.common.domain.PageRequest;
import cn.shujuhai.common.pluging.data.ResultVo;
import cn.shujuhai.workflow.domain.FormData;
import cn.shujuhai.workflow.service.FormDataService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author: ZhangDeZhong
 * @Date: 2025/3/11 09:42
 * @Description: 提供表【form_data(表单数据)】的操作接口
 **/
@RestController
@RequestMapping("/workflow/formData")
@RequiredArgsConstructor
public class FormDataController {

    final FormDataService formDataService;

    /**
     * 根据分页查询参数获取表单列表
     *
     * @param formId      表单ID
     * @param formData    搜索关键字（表单数据）
     * @param pageRequest
     * @return 表单数据列表的分页结果
     */
    @GetMapping("/list")
    public ResultVo<?> getFormDataList(
            @RequestParam Long formId,
            @RequestParam(defaultValue = "") Object formData,
            @Valid PageRequest pageRequest) {
        return this.formDataService.getFormDataList(formId, formData, pageRequest.getPageNum(), pageRequest.getPageSize());
    }

    /**
     * 添加表单信息
     *
     * @param formData 表单数据信息
     * @return 结果信息
     */
    @PostMapping("/addFormData")
    public ResultVo<?> addFormData(@RequestBody FormData formData) {
        return this.formDataService.addFormData(formData);
    }


    /**
     * 删除表单信息
     *
     * @param formDataId 表单数据ID
     * @return 结果信息
     */
    @PostMapping("/delete/{formDataId}")
    public ResultVo<?> deleteFormData(@PathVariable Long formDataId) {
        return this.formDataService.deleteFormData(formDataId);
    }

    /**
     * 批量删除表单信息
     *
     * @param formDataIds 表单数据ID集合
     * @return 结果信息
     */
    @PostMapping("/removeBatch")
    public ResultVo<?> removeBatchFormData(@RequestParam List<Long> formDataIds) {
        return this.formDataService.removeBatchFormData(formDataIds);
    }


    /**
     * 表单图片上传
     *
     * @param file 文件内容
     * @return 结果信息
     */
    @PostMapping("/uploadImg")
    public ResultVo<?> uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("formId") Long formId) {
        return this.formDataService.uploadImg(file, formId);
    }

    /**
     * 表单文件上传
     *
     * @param file 文件内容
     * @return 结果信息
     */
    @PostMapping("/uploadFile")
    public ResultVo<?> uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("formId") Long formId) {
        return this.formDataService.uploadFile(file, formId);
    }

    /**
     * 富文本编辑器图片上传
     *
     * @param files 文件内容
     * @return 结果信息
     */
    @PostMapping("/uploadIceImg")
    public ResultVo<?> uploadIceImg(@RequestParam("file[]") MultipartFile[] files, @RequestParam("formId") Long formId) {
        return this.formDataService.uploadIceImg(files, formId);
    }


}
